package com.polaris.live.adapter.message

import android.view.View
import com.blankj.utilcode.util.StringUtils
import com.polaris.live.R
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.constant.LiveConst
import com.polaris.live.databinding.AdapterFamilyMessageBinding
import com.polaris.live.resp.back_resp.AgencyMemberIndicatorResp
import com.polaris.live.translation.R.string
import com.polaris.live.widget.avatar.FrameImageUtils

/**
 * FamilyMessageAdapter
 *
 * @author Created by 半仙 on 2024/6/27/027 20:19
 */
class FamilyMessageAdapter : BaseBindingAdapter<AdapterFamilyMessageBinding, AgencyMemberIndicatorResp>() {

    init {
        addChildClickViewIds(R.id.goto_room)
        addChildClickViewIds(R.id.cons_head)
    }

    override fun convert(holder: VBViewHolder<AdapterFamilyMessageBinding>, item: AgencyMemberIndicatorResp) {
        holder.vb.apply {
            userRoundState.setState(item.memberUser)
            avFv.setFrameImage(FrameImageUtils.urlToFrameImageBean(item.memberUser.avatarFrame))
            avatar.setImageUrl(item.memberUser.avatar, item.memberUser.userId)
            val indicator = item.indicator

            val callWait = if (indicator.callWaitConnectRatio != null) {
                String.format("%.2f", ((indicator.callWaitConnectRatio).toDoubleOrNull() ?: 0.0) * 100)
            } else {
                0
            }
            val callValid = if (indicator.callValidRatio != null) {
                String.format("%.2f", ((indicator.callValidRatio).toDoubleOrNull() ?: 0.0) * 100)
            } else {
                0
            }
            tvConnection.text =
                "${StringUtils.getString(string.connection_rate, callWait.toString())}%"
            tvHavaConnection.text =
                "${StringUtils.getString(string.hava_connection_rate, callValid.toString())}%"
            tvTodayGet.text = StringUtils.getString(string.today_get_beans, "${indicator.todayIncome}")
            viewCountry.setCountry(item.memberUser.country)
            vipView.setVipLevel(item.memberUser.vipLevel)
            viewLevel.setCharmsLevel(item.memberUser.charms)
            nickname.text = item.memberUser.nickname
            if (item.memberUser.living == 1 && item.memberUser.liveType != LiveConst.Type.ONLY_MATCH) {
                gotoRoom.visibility = View.VISIBLE
            } else {
                gotoRoom.visibility = View.INVISIBLE
            }

        }
    }

}